package cn.hao.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.hao.model.TSet;
import cn.hao.service.TSetService;
@Controller
public class TSetController {

	@Autowired
	private TSetService tSetService;
	
	//首页
	@RequestMapping("/home")
	private String home(){
		return "/html/Set.html";
	}

	@RequestMapping("/selectSon/{id}.json")
	@ResponseBody
	private List<TSet> selectByParentId(@PathVariable Long id) {
		return this.tSetService.selectByParentId(id);
	}
	
	@RequestMapping("/getSet/{id}.json")
	@ResponseBody
	private TSet selectByPrimaryKey(@PathVariable Long id) {
		return this.tSetService.selectByPrimaryKey(id);
	}
	
	@RequestMapping("/addTSet")
	@ResponseBody
	private String addTSet(TSet tSet) {
		try {
			tSetService.addTSet(tSet);
		} catch (Exception e) {
			return "新增失败！";
		}
		return "新增成功！";
	}
	
	@RequestMapping("/updateTSet")
	@ResponseBody
	private String updateTSet(TSet tSet) {
		try {
			tSetService.updateByPrimaryKey(tSet);
		} catch (Exception e) {
			return "修改失败！";
		}
		return "修改成功！";
	}
	
	@RequestMapping("/delectTSet")
	@ResponseBody
	private String delectTSet(Long id) {
		try {
			tSetService.deleteByPrimaryKey(id);
		} catch (Exception e) {
			return "修改失败！";
		}
		return "修改成功！";
	}
}
